package com.gosophia.conference.action.scheme;

import java.util.Collections;
import java.util.List;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.conferenceManagement.scheme.dto.SchemeTransientStoreDTO;
import com.gosophia.conferenceManagement.scheme.ws.ConferenceSchemeWebService;
import com.gosophia.dataDictionary.dto.DataValueDTO;
import com.gosophia.dataDictionary.ws.DataDictionaryWebService;
import com.gosophia.userManagement.dto.UserInfoDTO;
import com.gosophia.userManagement.ws.UserManagementWebService;

/**
 * 处理方案起草Action，此Action用于刷方案起草页面
 * @author mayue
 * @since 2011-6-2
 *
 */
@SuppressWarnings("serial")
@Scope("prototype")
@Controller("DealSchemeSimulateAction")
public class DealSchemeSimulateAction extends BaseSupportAction{

	@Autowired
	private UserManagementWebService userManagementWebService;

	@Autowired
	private DataDictionaryWebService dataDictionaryWebService;
	
	@Autowired
	private ConferenceSchemeWebService conferenceSchemeWebService;
	
	private List<DataValueDTO> importanceList;
	
	private String userInfoString;
    
    private String importanceString;
    
    private String onlinePath;
    
    private String onlineVersion;
    
    private SchemeTransientStoreDTO schemeTransientStoreDTO;

    private Long jobId;
    
    private Long schemeTransientStoreId;
	@Override
	public String _execute() throws Exception {
	    
        //重要度
        importanceList = dataDictionaryWebService.findEnabledDataValueByEntryId(1014L);
        if(importanceList!=null){
            Collections.reverse(importanceList);
        }
		List<UserInfoDTO> userInfoDTOs = userManagementWebService.findAllUserInfoHasAccount();
		if(userInfoDTOs!=null && userInfoDTOs.size()!=0){
		    userInfoString=JSONArray.fromObject(userInfoDTOs).toString().replace("\"", "\\\"");
		}
		//从任务处理时：判断指定的jobId是否有对应的暂存，如果有跳转到编辑页面，如果没有跳转到新建页面
		if(jobId!=null){
		    schemeTransientStoreDTO = conferenceSchemeWebService.findTransientStoreByJobId(jobId);
		    if(schemeTransientStoreDTO!=null){
		        schemeTransientStoreId = schemeTransientStoreDTO.getSchemeTransientStoreId();
		    }
		    return "edit";
		}
		
		return SUCCESS;
	}
	public void setUserInfoString(String userInfoString) {
		this.userInfoString = userInfoString;
	}

	public String getUserInfoString() {
		return userInfoString;
	}


	public void setOnlinePath(String onlinePath) {
		this.onlinePath = onlinePath;
	}

	public String getOnlinePath() {
		return onlinePath;
	}

	public void setOnlineVersion(String onlineVersion) {
		this.onlineVersion = onlineVersion;
	}

	public String getOnlineVersion() {
		return onlineVersion;
	}

    public String getImportanceString() {
        return importanceString;
    }

    public void setImportanceString(String importanceString) {
        this.importanceString = importanceString;
    }
    public List<DataValueDTO> getImportanceList() {
        return importanceList;
    }
    public void setImportanceList(List<DataValueDTO> importanceList) {
        this.importanceList = importanceList;
    }
    public Long getJobId() {
        return jobId;
    }
    public void setJobId(Long jobId) {
        this.jobId = jobId;
    }
    public SchemeTransientStoreDTO getSchemeTransientStoreDTO() {
        return schemeTransientStoreDTO;
    }
    public void setSchemeTransientStoreDTO(
            SchemeTransientStoreDTO schemeTransientStoreDTO) {
        this.schemeTransientStoreDTO = schemeTransientStoreDTO;
    }
    public Long getSchemeTransientStoreId() {
        return schemeTransientStoreId;
    }
    public void setSchemeTransientStoreId(Long schemeTransientStoreId) {
        this.schemeTransientStoreId = schemeTransientStoreId;
    }
	
}
